package com.healthcare.admin.config;

import com.healthcare.admin.interceptor.JwtInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 作者：LSH
 * 日期：2020/1/13 17:49
 * 配置springboot得自定义拦截器
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 将自定义拦截器   添加到spring得拦截器zai中
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截器 放掉某些特定不需要校验token的路由
        registry.addInterceptor(new JwtInterceptor()).addPathPatterns("/admin/**").
                excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**")
         .excludePathPatterns("/admin/**")
        ;
    }

    // swagger 静态资源放行
    @Override
    public  void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
